#!/usr/bin/env python
#coding: iso-8859-1

"""Documentation for player.py

This file contains the player class,
with everything he needs to work.

project -- Rez: The Clone
author -- Edwood Grant
organization -- Binhex Tw.
version -- 1.00
since -- 7/07/2007 10:16:25
"""
import globals

#Panda specific imports for this module
from pandac.PandaModules import *
from direct.actor import Actor
#To handle Actors
#To handle intervals
from direct.interval.IntervalGlobal import *
from pandac.PandaModules import CollisionNode, CollisionSphere

from panda3d.physics import BaseParticleEmitter,BaseParticleRenderer
from panda3d.physics import PointParticleFactory,SpriteParticleRenderer
from panda3d.physics import LinearNoiseForce,DiscEmitter

from direct.particles.Particles import Particles
from direct.particles.ForceGroup import ForceGroup
from direct.particles.ParticleEffect import ParticleEffect



class spotlightTexture:
    """Class rezChar.

    Defines and implements a RezChar. Nothing special just a character
    in 0 position and animated, so it looks like its running
    """
    def __init__(self):
        """Constructor

        We are not doing anything special here, only when we decide to init
        """
        self.actor = Actor.Actor();
        self.node = render.attachNewNode("Enemy")

    def init(self):
        """Init Function
        """

        self.actor = Actor.Actor()
        self.actor.loadModel("../data/lvl/level1/cha/spot.egg")
        #self.actor.reparentTo(globals.PLAYER)

#        self.actor.setTransparency(1)
#        self.duckTexs = self.loadTextureMovie(119, 'spoanim/spotanim0',
#                                              'jpg', padding = 3)
#        self.duckTask = taskMgr.add(self.textureMovie, "duckTask")
#        self.duckTask.fps = 60
#        #self.duckPlane is the object whose texture should be changed
#        self.duckTask.obj = self.actor
#        self.duckTask.textures = self.duckTexs


    def textureMovie(self, task):
    #Here we calculate the current frame number by multiplying the current time
    #(in seconds) by the frames per second variable we set earlier
        currentFrame = int(task.time * task.fps)

    #Now we need to set the current texture on task.obj, which is the object
    #we specified earlier when we loaded the duck and explosion.
    #We will set its texture to one of the textures in the list we defined
    #earlier in task.textures.

    #Since we want the movie to loop, we need to reset the image index when it
    #reaches the end. We do this by performing a remainder operation (modulo,
    #"%" in python) on currentFrame with the number of frames, which is the
    #length of our frame list (len(task.textures)).
    #This is a common programming technique to achieve looping as it garuntees
    #a value in range of the list
        task.obj.setTexture(task.textures[currentFrame % len(task.textures)], 1)
        return task.cont          #Continue the task indefinitely

    #Our custom load function to load the textures needed for a movie into a
    #list. It assumes the the files are named
    #"path/name<serial number>.extention"
    #It takes the following arguments
    #Frames: The number of frames to load
    #name: The "path/name" part of the filename path
    #suffix: The "extention" part of the path
    #padding: The number of digit the serial number contians:
    #         e.g. if the serial number is 0001 then padding is 4
    def loadTextureMovie(self, frames, name, suffix, padding = 1):
    #The following line is very complicated but does a lot in one line
    #Here's the explanation from the inside out:
    #first, a string representing the filename is built an example is:
    #"path/name%04d.extention"
    #The % after the string is an operator that works like C's sprintf function
    #It tells python to put the next argument (i) in place of the %04d
    #For more string formatting information look in the python manual
    #That string is then passed to the loader.loadTexture function
    #The loader.loadTexture command gets done in a loop once for each frame,
    #And the result is returned as a list.
    #For more information on "list comprehensions" see the python manual
        return [loader.loadTexture(("../data/lvl/level1/cha/" + name+"%0"+str(padding)+"d."+suffix) % i)
            for i in range(frames)]
